package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "车辆管理")
@Slf4j
@Validated
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @ApiOperation("车辆列表查询")
    @GetMapping("select")
    public JsonResult selectAll(@Validated VehicleQuery vehicleQuery){
        log.debug("controller:车辆列表查询: vehicleQuery={}",vehicleQuery);
        List<VehicleVO> list =vehicleService.selectAll(vehicleQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("保存车辆")
    @PostMapping("save")
    public JsonResult saveVehicle(@Validated VehicleSaveParam vehicleSaveParam){
        log.debug("controller:保存车辆: vehicleSaveParam={}",vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除车辆")
    @PostMapping("delete/{vehicleId}")
    public JsonResult deleteVehicle(@PathVariable Long vehicleId){
        log.debug("controller:删除车辆: vehicleId={}",vehicleId);
        vehicleService.deleteVehicle(vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{vehicleId}")
    public JsonResult unbindGeofence(@PathVariable Long vehicleId){
        log.debug("controller:解除围栏绑定: vehicleId={}",vehicleId);
        vehicleService.unbindGeofence(vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("bind/{geoId}/{vehicleId}")
    public JsonResult bindGeofence(@PathVariable Long geoId,@PathVariable Long vehicleId){
        log.debug("controller:绑定围栏: geoId={},vehicleId={}",geoId,vehicleId);
        vehicleService.bindGeofence(geoId,vehicleId);
        return JsonResult.ok();
    }
}
